<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="赛事名称" prop="eventName">
        <el-input
          v-model="queryParams.eventName"
          placeholder="请输入赛事名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="比赛场地" prop="competitionVenue">
<!--        <el-input-->
<!--          v-model="queryParams.competitionVenue"-->
<!--          placeholder="请输入比赛场地"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
        <el-select
          v-model="queryParams.competitionVenue"
          placeholder="请选择比赛场地" clearable>
          <el-option
            v-for="item in competitionVenueList1"
            :value="item.value"
            :label="item.label"
            :key="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="比赛项目" prop="competitionItems">
        <el-select v-model="queryParams.competitionItems" placeholder="请选择比赛项目" clearable>
          <el-option
            v-for="item in opations1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small " @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="small " @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:progress:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:progress:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:progress:remove']"
        >批量删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:progress:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table  border v-loading="loading" :data="progressList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="赛事id" align="center" prop="id" />
      <el-table-column label="赛事名称" align="center" prop="eventName" />
      <el-table-column label="所在赛区" align="center" prop="locatedArea" >
        <template slot-scope="scope">
          {{scope.row.locatedArea == '1' ? '北京赛区':scope.row.locatedArea == '2' ? '北京延庆赛区':scope.row.locatedArea == '3' ? '张家口赛区':'--'  }}
        </template>
      </el-table-column>
      <el-table-column label="比赛场地" align="center" prop="competitionVenue" :formatter="formatterCompetitionVenue" />
      <el-table-column label="比赛项目" align="center" prop="competitionItems" :formatter="projectNameFormatter">
      </el-table-column>
      <el-table-column label="赛事秩序" align="center" prop="tournamentOrder" />
      <el-table-column label="注意事项" align="center" prop="precautions" />
<!--      <el-table-column label="赛事进度" align="center" prop="tournamentProgress" :formatter="tournamentProgressFormatter"/>-->

      <el-table-column label="操作" align="center" width="270px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:progress:edit']"
          >修改</el-button>
            <el-button
              size="small"
              type="primary"
              icon="el-icon-collection-tag"
              @click="handleView(scope.row)"
              v-hasPermi="['system:progress:view']"
            >详情</el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:progress:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改赛事项目/进度对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="赛事名称" prop="eventName">
          <el-input v-model="form.eventName" placeholder="请输入赛事名称" />
        </el-form-item>
        <el-form-item label="所在赛区" prop="locatedArea">
          <el-select v-model="form.locatedArea" placeholder="请选择赛区">
          <el-option
            v-for="item in locatedAreaList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
          </el-select>
<!--          <el-input v-model="form.eventName" placeholder="请输入赛事名称" />-->
        </el-form-item>
        <el-form-item label="比赛场地" prop="competitionVenue">
          <el-select
            v-model="form.competitionVenue"
            placeholder="请选择比赛场地">
            <el-option
              v-for="item in competitionVenueList"
              :value="item.value"
              :label="item.label"
              :key="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="比赛项目" prop="competitionItems">
          <el-select v-model="form.competitionItems" placeholder="请选择比赛项目">
            <el-option
              v-for="item in opations"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="赛事秩序" prop="tournamentOrder">
          <el-input type="textarea" show-word-limit :row="4" maxlength="100" v-model="form.tournamentOrder" placeholder="请输入赛事秩序" />
        </el-form-item>
        <el-form-item label="注意事项" prop="precautions">
          <el-input type="textarea" show-word-limit :autosize="{ minRows: 4, maxRows: 6}" maxlength="150" v-model="form.precautions" placeholder="请输入注意事项" />
        </el-form-item>
<!--        <el-form-item label="赛事进度" prop="tournamentProgress">-->
<!--          <el-select v-model="form.tournamentProgress"  placeholder="请选择赛事进度" clearable>-->
<!--            <el-option-->
<!--            v-for="item in options"-->
<!--            :key="item.value"-->
<!--            :label="item.label"-->
<!--            :value="item.value"-->
<!--            >-->
<!--            </el-option>-->
<!--          </el-select>-->

<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProgress, getProgress, delProgress, addProgress, updateProgress } from "@/api/system/progress";

export default {
  name: "Progress",
  dicts: ['sys_oper_type'],
  data() {
    return {
      opations1:[
        {
          value: '1',
          label: '短道速滑'
        }, {
          value: '2',
          label: '速度滑冰'
        }, {
          value: '3',
          label: '花样滑冰'
        }, {
          value: '4',
          label: '冰球'
        }, {
          value: '5',
          label: '冰壶'
        }, {
          value: '6',
          label: '雪车'
        }, {
          value: '7',
          label: '钢架雪车'
        }, {
          value: '8',
          label: '雪橇'
        }, {
          value: '9',
          label: '冬季两项'
        }, {
          value: '10',
          label: '高山滑雪'
        }, {
          value: '11',
          label: '自由式滑雪'
        }, {
          value: '12',
          label: '单板滑雪'
        }, {
          value: '13',
          label: '越野滑雪'
        }, {
          value: '14',
          label: '跳台滑雪'
        },{
          value: '15',
          label: '北欧两项'
        }
      ],
      opations:[
        {
          value: '1',
          label: '短道速滑'
        }, {
          value: '2',
          label: '速度滑冰'
        }, {
          value: '3',
          label: '花样滑冰'
        }, {
          value: '4',
          label: '冰球'
        }, {
          value: '5',
          label: '冰壶'
        }, {
          value: '6',
          label: '雪车'
        }, {
          value: '7',
          label: '钢架雪车'
        }, {
          value: '8',
          label: '雪橇'
        }, {
          value: '9',
          label: '冬季两项'
        }, {
          value: '10',
          label: '高山滑雪'
        }, {
          value: '11',
          label: '自由式滑雪'
        }, {
          value: '12',
          label: '单板滑雪'
        }, {
          value: '13',
          label: '越野滑雪'
        }, {
          value: '14',
          label: '跳台滑雪'
        },{
          value: '15',
          label: '北欧两项'
        }
      ],
      options:[
        {
          value: 1,
          label: '待开始'
        }, {
          value: 2,
          label: '进行中'
        }, {
          value: 3,
          label: '已完成'
        }
      ],
      locatedAreaList:[
        {
          value: '1',
          label:'北京赛区'
        },
        {
          value: '2',
          label:'北京延庆赛区'
        },
        {
          value: '3',
          label:'张家口赛区'
        }
      ],
      competitionVenueList1:[
        {
          value: '1',
          label: '首都体育馆'
        },
        {
          value: '2',
          label: '国家速滑馆'
        },
        {
          value: '3',
          label: '国家体育馆'
        },
        {
          value: '4',
          label: '五棵松体育中心'
        },
        {
          value: '5',
          label: '国家游泳中心'
        },
        {
          value: '6',
          label: '首钢滑雪大跳台中心'
        },
        {
          value: '7',
          label: '国家雪车雪橇中心'
        },
        {
          value: '8',
          label: '国家高山滑雪中心'
        },
        {
          value: '9',
          label: '云顶滑雪公园'
        },
        {
          value: '10',
          label: '国家跳台滑雪中心'
        },
        {
          value: '11',
          label: '国家越野滑雪中心'
        },
        {
          value: '12',
          label: '国家冬季两项中心'
        }
      ],
      competitionVenueList:[
        {
          value: '1',
          label: '首都体育馆'
        },
        {
          value: '2',
          label: '国家速滑馆'
        },
        {
          value: '3',
          label: '国家体育馆'
        },
        {
          value: '4',
          label: '五棵松体育中心'
        },
        {
          value: '5',
          label: '国家游泳中心'
        },
        {
          value: '6',
          label: '首钢滑雪大跳台中心'
        },
        {
          value: '7',
          label: '国家雪车雪橇中心'
        },
        {
          value: '8',
          label: '国家高山滑雪中心'
        },
        {
          value: '9',
          label: '云顶滑雪公园'
        },
        {
          value: '10',
          label: '国家跳台滑雪中心'
        },
        {
          value: '11',
          label: '国家越野滑雪中心'
        },
        {
          value: '12',
          label: '国家冬季两项中心'
        }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 赛事项目/进度表格数据
      progressList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        eventName: null,
        locatedArea: null,
        competitionVenue: null,
        competitionItems: null,
      },
      // 表单参数
      form: {
        tournamentProgress: 1
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //比赛场地
    formatterCompetitionVenue(row,cloumn){
      switch(row.competitionVenue){
        case '1':
          return '首都体育馆';
          break;
        case '2':
          return '国家速滑馆';
          break;
        case '3':
          return '国家体育馆';
          break;
        case '4':
          return '五棵松体育中心';
          break;
        case '5':
          return '国家游泳中心';
          break;
        case '6':
          return '首钢滑雪大跳台中心';
          break;
        case '7':
          return '国家雪车雪橇中心';
          break;
        case '8':
          return '国家高山滑雪中心';
          break;
        case '9':
          return '云顶滑雪公园';
          break;
        case '10':
          return '国家跳台滑雪中心';
          break;
        case '11':
          return '国家越野滑雪中心';
          break;
        case '12':
          return '国家冬季两项中心';
          break;
        default:
          return '未知';
      }
    },
    //项目名称
    projectNameFormatter(row,cloumn){
      switch(row.competitionItems){
        case '1':
          return '短道速滑';
          break;
        case '2':
          return '速度滑冰';
          break;
        case '3':
          return '花样滑冰';
          break;
        case '4':
          return '冰球';
          break;
        case '5':
          return '冰壶';
          break;
        case '6':
          return '雪车';
          break;
        case '7':
          return '钢架雪车';
          break;
        case '8':
          return '雪橇';
          break;
        case '9':
          return '冬季两项';
          break;
        case '10':
          return '高山滑雪';
          break;
        case '11':
          return '自由式滑雪';
          break;
        case '12':
          return '单板滑雪';
          break;
        case '13':
          return '跳台滑雪';
          break;
        case '14':
          return '越野滑雪';
          break;
        case '15':
          return '北欧两项';
          break;
        default:
          return '未知';
      }
    },
    //项目进度
    tournamentProgressFormatter(row,cloumn){
      switch(row.tournamentProgress){
        case 1:
          return '待开始';
          break;
        case 2:
          return '进行中';
          break;
        case 3:
          return '已完成';
          break;
      }
    },
    /** 查询赛事项目/进度列表 */
    getList() {
      this.loading = true;
      listProgress(this.queryParams).then(response => {
        this.progressList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        eventName: null,
        country: null,
        locatedArea: null,
        competitionVenue: null,
        tournamentOrder: null,
        precautions: null,
        tournamentProgress: 1,
        competitionItems: null,
        extField1: null,
        extField2: null,
        isDeleted: null,
        createUserid: null,
        createUsername: null,
        createTime: null,
        serverIp: null,
        updateUserid: null,
        updateUsername: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加赛事项目/进度";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProgress(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改赛事项目/进度";
      });
    },
    handleView(row){
      this.$router.push(
        {
          name:'evenProjectDetail',
          query:{
            id: row.id,
            locatedArea: row.locatedArea,
            competitionItems: row.competitionItems,
            competitionVenue:row.competitionVenue
          }
        }
      )
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProgress(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProgress(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除赛事项目/进度编号为"' + ids + '"的数据项？').then(function() {
        return delProgress(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/progress/export', {
        ...this.queryParams
      }, `progress_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
